package com.czk.utlls;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/8/3 15:36
 */
@Component
public class QrCodeTicketUtil {
    @Value("${tempQrCodeUrl}")
    private String tempQrCodeUrl;
    @Autowired
    private TokenUtil tokenUtil;

    public String getQrCodeTicket() {
        tempQrCodeUrl = tempQrCodeUrl.replace("TOKEN", tokenUtil.getToken().getAccessToken());
        // 数据
        String data = "{\"expire_seconds\": 604800, " +
                "\"action_name\": \"QR_STR_SCENE\", " +
                "\"action_info\": {\"scene\": {\"scene_STR\": \"czk真帅\"}}}";
        String result = WeChatUtil.post(tempQrCodeUrl, data);
        // 取出ticket
        JSONObject jsonObject = JSONObject.parseObject(result);
        String ticket = jsonObject.getString("ticket");
        System.out.println(ticket);
        return ticket;
    }
}
